﻿<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <style type="text/css">
        body {
            padding: 20px
        }
    </style>
    <link rel="stylesheet" href="index.css">

    <script src="/htmx.js"></script>
    <script type="text/javascript">

    </script>
</head>

<body>
    <button hx-get="/api/index.aardio" 
        hx-swap="innerHTML" 
        hx-trigger="click" 
        hx-target="#info-div"  
        hx-vals='javascript:{myVal: "\
        有以下几种方法指定请求参数：\
        1、在这里直接指定 JSON 作为请求参数。\
        2、使用 javascript: 返回一个 JS 对象作为请求参数。\
        3、如果当前节点是 input，则 name 指定参数名。\
        4、如果当前节点是 form ，则表单内部所有控件的数据作为请求参数。"}'  
        hx-indicator="#indicator">
        点这里发送 GET 请求
    </button><br>

    <!-- 
        上面的 hx-indicator="#indicator" 用 CSS 选择器指定了提交时显示的节点，
        由 index.css 中的 .htmx-request.htmx-indicator 样式指定了提交时切换为显示样式。
        注意 aardio 后端是多线程的，执行耗时操作不会阻塞网页前端。
    -->
    <img id="indicator" class="htmx-indicator" src="/images/loading.gif"/>

    <div id="info-div">
        使用 htmx 每个 HTML 节点都可以发送 HTTP 请求，<br>
        每个 HTML 节点都可以单独刷新显示服务端返回的 HTML。<br>
        <br> 
        不要为了不写 JavaScript 而不写 JavaScript：<br>  
        <button onclick="aardio.getFile().then( 
            v=> { if(v) document.getElementById('info-div').innerText = v; }
            )">
            JavaScript 直接调用 aardio 函数打开本地文件</button>
    </div><br>

    <input type="text" 
        name="q" 
        hx-post="/api/index.aardio" 
        hx-trigger="keyup changed delay:500ms"
        hx-target="#search-results" 
        placeholder="请输入关键词发送 POST 请求 ..."
        style="width:300px"><br>
    <div id="search-results"></div>
    <br>
    <a href="https://mp.weixin.qq.com/s/UTiu5gXJ7j-hKnewhhF5sA" target="_blank">htmx.js 快速入门</a>
    <canvas id="mycanvas" width="1000" height="700" style="position: fixed;left:0px;top:0px;z-index: -1;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvas = document.getElementById("mycanvas"); //绘图区域
        let context = canvas.getContext("2d"); //绘图上下文
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        let gPaint = new FCPaint(); //绘图对象
        gPaint.canvas = canvas;
        scaleCanvas(gPaint);
        //判断是否移动端
        gPaint.isMobile = isMobileMode();
        if (gPaint.isMobile) {
            gPaint.scaleFactorX = 2.5;
            gPaint.scaleFactorY = 2.5;
        }
        
        gPaint.defaultUIStyle = "dark";
        addDefaultEvent(canvas, gPaint);
        /*
         * 重置大小
         */
        let resizeAll = function () {
            try {
                canvas.width = document.documentElement.clientWidth;
                canvas.height = document.documentElement.clientHeight;
                scaleCanvas(gPaint);
                updateViewDefault(gPaint.views);
            } catch (err) {
                
            }
            invalidate(gPaint);
        };
        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();
        };
        //解析加载XML
        let xml = `<?xml version="1.0" encoding="UTF-8"?>
  <html xmlns="facecat">
    <body>
      <div dock="fill" backcolor="rgb(140,192,81)">
        <div name="Div" text="Div" location="368,127" size="247,326" align="center" vertical-align="middle" backcolor="rgb(170,178,189)" cornerradius="10">
          <input type="text" name="TextBox" location="14,18" size="220,45" cornerradius="0" bordercolor="rgb(0,0,0)" backcolor="rgb(42,48,72)" font="Default,30.0" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnAC" text="AC" location="14,69" size="55,48" font="Default,18.0" backcolor="rgb(62,72,95)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnAddSub" text="+/-" location="69,69" size="55,48" font="Default,18.0" backcolor="rgb(62,72,95)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnMod" text="%" location="124,69" size="55,48" font="Default,18.0" backcolor="rgb(62,72,95)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnDivide" text="÷" location="179,69" size="55,48" font="Default,18.0" backcolor="rgb(254,159,11)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum7" text="7" location="14,117" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum8" text="8" location="69,117" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum9" text="9" location="124,117" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnMulti" text="×" location="179,117" size="55,48" font="Default,18.0" backcolor="rgb(254,159,11)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum4" text="4" location="14,165" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum5" text="5" location="69,165" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum6" text="6" location="124,165" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnSub" text="-" location="179,165" size="55,48" font="Default,18.0" backcolor="rgb(254,159,11)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum1" text="1" location="14,213" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum2" text="2" location="69,213" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum3" text="3" location="124,213" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnAdd" text="+" location="179,213" size="55,48" font="Default,18.0" backcolor="rgb(254,159,11)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnNum0" text="0" location="14,261" size="110,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnDot" text="." location="124,261" size="55,48" font="Default,18.0" backcolor="rgb(93,103,121)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
          <input type="button" name="btnResult" text="=" location="179,261" size="55,48" font="Default,18.0" backcolor="rgb(254,159,11)" bordercolor="rgb(0,0,0)" textcolor="rgb(255,255,255)"/>
        </div>
      </div>
    </body>
  </html>`;
        renderFaceCat(gPaint, xml);
    </script>
</body>

</html>